#include "vcoreglobal.h"

#include "vglunchengineloop.h"

// 全局变量定义
bool GIsRequestingExit = false;
bool GIsEditor = true;

VLevelEditor* LevelEditor = nullptr;

// VGRenderCommandQueue静态成员初始化
VGRenderCommandQueue* VGRenderCommandQueue::s_Instance = nullptr;

VGRenderCommandQueue& VGRenderCommandQueue::Get()
{
    if (!s_Instance)
    {
        s_Instance = new VGRenderCommandQueue();
    }
    return *s_Instance;
}

void VGRenderCommandQueue::EnqueueCommand(VGRenderCommand* command)
{
    if (command)
    {
        m_Commands.push_back(command);
    }
}

void VGRenderCommandQueue::ExecuteCommands()
{
    // 执行传统的VGRenderCommand
    for (auto* command : m_Commands)
    {
        if (command)
        {
            command->Execute();
            delete command;
        }
    }
    m_Commands.clear();
    
    // 执行基于Qt+UE4的lambda命令
    for (auto& lambdaCommand : m_LambdaCommands)
    {
        if (lambdaCommand)
        {
            lambdaCommand();
        }
    }
    m_LambdaCommands.clear();
}

void VGRenderCommandQueue::ClearCommands()
{
    for (auto* command : m_Commands)
    {
        delete command;
    }
    m_Commands.clear();
    
    // 清理lambda命令
    m_LambdaCommands.clear();
}

// 渲染命令任务类
class VGRenderTask : public QRunnable
{
public:
    VGRenderTask(std::function<void()> command) : m_Command(command) {}
    
    void run() override
    {
        if (m_Command)
        {
            m_Command();
        }
    }
    
private:
    std::function<void()> m_Command;
};

void VGRenderCommandQueue::ExecuteCommandsInThreadPool()
{
}

qint32 EditorInit(IVGEngineLoop& EngineLoop)
{

    
	return 0;
}
